package com.kdl.webconfig.converter;

import com.kdl.webconfig.vo.config.ButtonConfigVO;
import com.kdl.webconfig.entity.ButtonConfig;
import com.kdl.webconfig.entity.CustomInfo;
import com.kdl.webconfig.entity.PicConfig;
import com.kdl.webconfig.vo.config.CustomInfoVO;
import com.kdl.webconfig.vo.config.PicConfigSaveReq;

import java.util.Date;
import java.util.Objects;

/**
 * @author 王成杰
 * @description TODO
 * @date 2022-09-05 下午4:25
 */

public class PojoConvert {

    public static PicConfig parsePicConfig(PicConfigSaveReq picConfigSaveReq){
        if(Objects.isNull(picConfigSaveReq)){
            return null;
        }
        PicConfig picConfig = new PicConfig();
        picConfig.setId(picConfigSaveReq.getId());
        picConfig.setPicUrl(picConfigSaveReq.getPicUrl());
        picConfig.setTitle(picConfigSaveReq.getTitle());
        picConfig.setComment(picConfigSaveReq.getComment());
        picConfig.setState(picConfigSaveReq.getState());
        picConfig.setSort(picConfigSaveReq.getSort());
        picConfig.setType(picConfigSaveReq.getType());
        return picConfig;
    }

    public static CustomInfo parseCustomInfo(CustomInfoVO customInfoVO){
        if(Objects.isNull(customInfoVO)){
            return null;
        }
        CustomInfo customInfo = new CustomInfo();
        customInfo.setCustomName(customInfoVO.getCustomName());
        customInfo.setCustomPhone(customInfoVO.getCustomPhone());
        customInfo.setCustomEmail(customInfoVO.getCustomEmail());
        customInfo.setMessage(customInfoVO.getMessage());
        customInfo.setDeleteFlag(0);
        customInfo.setCreateTime(new Date());
        customInfo.setUpdateTime(new Date());
        return customInfo;
    }

    public static ButtonConfig parseButtonConfig(ButtonConfigVO buttonConfigVO) {
        if(Objects.isNull(buttonConfigVO)){
            return null;
        }
        ButtonConfig buttonConfig = new ButtonConfig();
        buttonConfig.setId(buttonConfigVO.getId());
        buttonConfig.setPicId(buttonConfigVO.getPicId());
        buttonConfig.setComment(buttonConfigVO.getComment());
        buttonConfig.setLinkUrl(buttonConfigVO.getLinkUrl());
        return buttonConfig;
    }

}
